from math import ceil
from math import floor
from typing import List


class Solution:
    def minimizeError(self, prices: List[str], target: int) -> str:
        prices = [float(price) for price in prices]

        min_price = sum(floor(price) for price in prices)
        max_price = sum(ceil(price) for price in prices)

        if not min_price <= target <= max_price:
            return "-1"

        ceil_num = target - min_price  # 向下取整数量
        floor_num = max_price - target  # 向上取整数量

        floor_val = [price - floor(price) for price in prices if price != floor(price)]
        ceil_val = [ceil(price) - price for price in prices if price != ceil(price)]

        floor_val.sort()
        ceil_val.sort()

        return "{0:.3f}".format(sum(floor_val[:floor_num]) + sum(ceil_val[:ceil_num]))


if __name__ == "__main__":
    # "1.000"
    print(Solution().minimizeError(prices=["0.700", "2.800", "4.900"], target=8))

    # "-1"
    print(Solution().minimizeError(prices=["1.500", "2.500", "3.500"], target=10))
